﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel.Dispatcher;
using System.Xml;

namespace RockBus.DataContracts
{
    [CollectionDataContract(Namespace = StringConstants.RockBusNamespace)]
    public class NamespaceInfoCollection : Collection<NamespaceInfo>
    {
        public NamespaceInfo this[string prefix]
        {
            get
            {
                return this.FirstOrDefault<NamespaceInfo>((ni) => StringComparer.InvariantCultureIgnoreCase.Compare(ni.Prefix, prefix) == 0);
            }
        }

        public XmlNamespaceManager GetXmlNamespaceManager()
        {
            XmlNamespaceManager xmlNamespaces = new XPathMessageContext();
            foreach (NamespaceInfo ni in this)
            {
                xmlNamespaces.AddNamespace(ni.Prefix, ni.Namespace);
            }
            return xmlNamespaces;
        }
    }
}